package com.twu.biblioteca.command;

import com.twu.biblioteca.Library;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.PrintStream;

public class ReturnBookCommand implements Command {
    PrintStream printStream;
    BufferedReader reader;
    Library library;

    public ReturnBookCommand(PrintStream printStream, BufferedReader reader, Library library) {
        this.printStream = printStream;
        this.reader = reader;
        this.library = library;
    }

    @Override
    public String commandName() {
        return "return book";
    }

    @Override
    public void execute() throws IOException {
        printStream.println("Which book would you like to return?");
        String bookIdx = reader.readLine();
        boolean success = library.returnBook(bookIdx);
        if (success) {
            printStream.println("Thank you for returning the book.");
        } else {
            printStream.println("That is not a valid book to return.");
        }
    }
}
